use Test::More 'no_plan';

use lib "../lib/cpp", "../lib/ioc", "../lib/toolkit", '../lib/message';
use TinyMessage;

use Signature;

use CHeaderParser;
use CProject;
use CConstructorMatcher;
use CCodeGenerator;
use FindBin;

use IProject;
use IModule;
use IProvider;
use ICreator;

use TestHelper;

my $source = "$FindBin::Bin/cpp/test-namespace/";
my $out = $source . "generated";

my $iproject = new IProject();
$iproject->load(new CProject($source));

my @modules = @{ $iproject->modules() };

is (@modules, 1);

my $module = $modules[0];
my $moduleClasses = $module->moduleClasses();

is($moduleClasses->keys(), 1);

ok($moduleClasses->exists('Log::LogSerivce'));
#ok($moduleClasses->exists('SINGLETON< Log::LogSerivce >'));

my $creator = undef;

{
	$creator = $module->class_creator('Log::LogSerivce');
	ok($creator);
	is(signature($creator->class()->to_carg('*')), 'Log::LogSerivce*');
	is(stringfy($creator->class()), 'Log__LogSerivce');
	is($creator->ctor()->count(), 0);
}

#{
#	$creator = $module->class_creator('SINGLETON< Log::LogSerivce >');
#	ok($creator);
#	is(signature($creator->class()->to_carg('*')), 'SINGLETON< Log::LogSerivce >*');
#	is(stringfy($creator->class()), 'SINGLETON_lt_Log__LogSerivce_gt_');
#	is($creator->ctor()->count(), 0);
#}

is_deeply($module->includes_rel($out), ['../source/AppModule.h', '../source/services/LogService.h']);
is_deeply($module->providers(), [new IProvider( 
		class_sig('Log::LogSerivce', []),  
		class_sig('Log::LogSerivce', []), 
		'getLogService', 's',
		class_sig('SINGLETON< Log::LogSerivce >', []) )]);
		
CCodeGenerator::generate($module, $out);

isSame($out . "/Module__AppMoudle.cpp", $out . "/Module__AppMoudle.real");
